<?php

/**
 * 开发者自定义函数文件
 */
// 获取内容中的iframe
/*function dr_get_content_imgs($value) {

    $rt = [];
    if (preg_match_all('/<img title="\d" alt="\d" src="(.+)"/iU', $value, $imgs)) {
        $imgs[1] = array_unique($imgs[1]);
			foreach ($imgs[1] as $i => $img) {
				$rt[] = dr_file(trim($img, '"'));
			}
    }
    return $rt;
}*/

function dr_get_content_imgs($value) {

    $rt = [];
    if (preg_match_all("/(".$attr.")=([\"|']?)([^ \"'>]+\.(".$ext.")([\s\S]*))\\2/i", $value, $imgs)) {
        $imgs[1] = array_unique($imgs[1]);
			foreach ($imgs[1] as $i => $img) {
				$rt[] = dr_file(trim($img, '"'));
			}
    }
    return $rt;
}
// 去除内容中的图片
function dr_get_content_quimgs($html) {
    if (!$html) {
        return '';
    }
    $p = array("/<[a|A][^>]+(topic=\"true\")+[^>]*+>#([^<]+)#<\/[a|A]>/",
        "/<[a|A][^>]+(data=\")+([^\"]+)\"[^>]*+>[^<]*+<\/[a|A]>/",
        "/<[img|IMG][^>]+(src=\")+([^\"]+)\"[^>]*+>/","/<br>/");
    $t = array('topic{data=$2}','$2','');
    $html = preg_replace($p, $t, $html);
	//过滤标签
    //$html = strip_tags($html, "");
    
    return $html;
}
// 伪静态开关
function dr_son_url($data) {
	$config = \Phpcmf\Service::C()->get_cache('module-'.SITE_ID.'-quan', 'setting', 'param');
	if (isset($config['son_rewrite']) && $config['son_rewrite'] && $config['son_rule']) {
		$mod = \Phpcmf\Service::C()->module;
		return \Phpcmf\Service::L('router')->get_url_value(
			$data,
			$config['son_rule'],
			\Phpcmf\Service::L('router')->url_prefix('rewrite', $mod, $data, 0)
		);
	}
	return SITE_URL.'index.php?s=quan&c=son&id='.$data['id'];
}
function dr_jifen_url($data) {
	/*$config = \Phpcmf\Service::C()->get_cache('module-'.SITE_ID.'-quan', 'setting', 'param');
	if (isset($config['son_rewrite']) && $config['son_rewrite'] && $config['son_rule']) {
		$mod = \Phpcmf\Service::C()->module;
		return \Phpcmf\Service::L('router')->get_url_value(
			$data,
			$config['son_rule'],
			\Phpcmf\Service::L('router')->url_prefix('rewrite', $mod, $data, 0)
		);
	}*/
	return SITE_URL.'index.php?s=quan&c=jifen&id='.$data['id'];
}
// 会员伪静态开关
function d_huiyuan_url($data) {

	$udata = \Phpcmf\Service::M('app')->get_config('huiyuan');
	//dr_debug('会员', $udata);

	$uidurl = dr_url('huiyuan/show/index',['uid' => $data]);
	$dataseo = '/u/'.$data;
	if ($udata['home']['seo'] == 0) {
		return $dataseo;
	}
	return $uidurl;
	//return '/index.php?s=quan&c=son&id='.$data;
}
// 列表的点赞数据+++++++++++

function zan($data) {
    $uid = (int)\Phpcmf\Service::L('input')->get('uid');
    $rt = [];
    // 这里根据项目的$data输出格式来定义PHP的数据写法，
    // 每个接口的写法几乎不一样，下面是测试例子
    if ($data) {
            foreach ($data as $t) {
                $zanzhi = \Phpcmf\Service::M()->db->table('1_quan_form_son_zan')->where('cid', $t['id'])->where('uid', $uid)->get()->getRowArray();
                if($zanzhi) {
                    $zanzhi = 1;
                    $title = "已赞";
                } else {
                    $zanzhi = 0;
                    $title = "未赞";
                }
                
                $rt[] = [
                    'id' => $t['id'], // id号
                    'zanzhi' => $zanzhi,
                    'title' => $title,
                    'uid' => $uid
                ];
            }
        }
    
    return $rt;
}
function quanbeijing($data) {
	if($data){
		$rt = dr_thumb($data);
	} else {
		$rt = '';
	}
	return $rt;
}